﻿package sun.freelancer.throwdart 
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import sun.freelancer.throwdart.model.PageView;
	import sun.freelancer.throwdart.view.BaseView;
	
	/**
	 * ...
	 * @author zSun
	 */
	public class Main extends MovieClip 
	{
		private static var _api: Main;
		
		private var currentView: BaseView;
		public function Main():void 
		{
			_api = this;
			// hide all views
			_api.mcWelcome.visible = true;
			_api.mcChoose.visible = true;
			_api.mcGame.visible = true;
			_api.mcResult.visible = true;
			
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			showPageView(PageView.WELCOME);
		}
		
		public function showPageView(pageName: String): void
		{
			if (currentView) currentView.visible = false;
			switch(pageName)
			{
				case PageView.WELCOME:
					currentView = _api.mcWelcome;
				break;
				case PageView.CHOOSE:
					currentView = _api.mcChoose;
				break;
				case PageView.GAME:
					currentView = _api.mcGame;
				break;
				case PageView.RESULT:
					currentView = _api.mcResult;
				break;
			}
			if(currentView) currentView.visible = true;
		}
		
		static public function get api():Main { return _api; }
		
		static public function set api(value:Main):void 
		{
			_api = value;
		}
		
	}
	
}